home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ultratk.exe / ULTRA.C < prev    next >
C/C++ Source or Header  |  1991-08-19  |  8KB  |  265 lines

  1. /* ultra.c 
  2.    
  3.    These functions are Turbo C implementations of many of the extended
  4.    BIOS routines provided with UltraVision(r), version 2.0.  Several 
  5.    of the functions herein make use of the files  VIDEO.C  &  VIDEO.H  
  6.    recently uploaded by the author. 
  7.    
  8.    COMPILE SEPARATELY. LINK EXE FILES WITH VIDEO.OBJ & ULTRA.OBJ
  9.    
  10.    Tom Kallal, 4150 Sovereign Way, Salt Lake City UT 84124.
  11. */
  12.  
  13.  
  14. #include "ultra.h"
  15. #include "video.h"
  16. #include <dos.h>
  17. #include <conio.h>
  18.  
  19. extern  video_status  CRT;                /* a global */
  20.  
  21.  
  22. int    ultra_loaded   ( void )
  23. {
  24.    /* Return 1 if UV is loaded,  0 if not loaded.   */   
  25.    
  26.    _AH = 0xcc;                            /* Get UV status */
  27.    _AL = 0x00;
  28.    geninterrupt ( 0x10 );
  29.    
  30.    if ( _CX == 0xabcd ) return ( TRUE ); /* UV is loaded */
  31.    else                 return ( FALSE );
  32. }
  33.  
  34.  
  35. int   ultra_active   ( void )
  36. {
  37.    /* Return 1 if UV is loaded AND active, 0 otherwise.   */   
  38.  
  39.    _AH = 0xcc;                            /* Get UV status */
  40.    _AL = 0x00;
  41.    geninterrupt ( 0x10 );
  42.  
  43.    if (( _AL==0 )&&( _CX==0xabcd )) return ( TRUE );                  
  44.    else                             return ( FALSE );
  45. }
  46.    
  47.  
  48. int   get_ultra_card   ( void )
  49. {
  50.    /* Return the video card code ( 0 - 27 ) if UltraVision is loaded,
  51.       else return FAIL.  If needed, this function should be called just 
  52.       once at startup.
  53.    */
  54.    
  55.    _AH = 0xcc;                            /* Get UV status */
  56.    _AL = 0x00;
  57.    geninterrupt ( 0x10 );
  58.  
  59.    if ( _CX == 0xabcd ) return ( _AH );   /* if loaded, return card # */
  60.    else                 return ( FAIL );
  61. }
  62.  
  63.  
  64. int  get_ultra_mode  ( void )
  65. {
  66.    /* Return the current UV text mode if UV is loaded and active,
  67.       else return  FAIL . 
  68.    */
  69.    
  70.    if ( ultra_active() ) {    /* Is UV loaded AND active ? */
  71.    
  72.       _AH = 0xcd;
  73.       _AL = 0x04;
  74.       geninterrupt ( 0x10 );
  75.       
  76.       return _AL;
  77.    }   
  78.    return (FAIL);
  79. }      
  80.  
  81.  
  82. /* NOTE: The rest of the functions in this file refer to variables 
  83.          and functions found in VIDEO.C and VIDEO.H.  With the
  84.          exception of the functions bump_rows() and bump_cols(), 
  85.          it would be easy to remove these references and still have 
  86.          a complete working set of functions for UltraVision text 
  87.          modes.  The idea of combining this file with VIDEO.C is to
  88.          have a complete set of Turbo C text mode video functions 
  89.          that are compatible with any monitor, whether running 
  90.          UltraVision or not.
  91. */
  92.  
  93. int   set_ultra_mode   ( int uv_mode )
  94. {
  95.    /* Set a special UV text mode.  Return the mode requested if successful, 
  96.       else return FAIL.  Calling this function directly requires knowing 
  97.       the video card in place and its mode capabilities.  
  98.    */   
  99.       
  100.    if ( ultra_active() ) {
  101.    
  102.       _AH = 0xcd;
  103.       _AL = uv_mode;                    /* set UV text mode */
  104.       geninterrupt ( 0x10 );
  105.  
  106.       if ( _AX != 0xcdcd ) {            /* CDCD == mode error */
  107.  
  108.          get_video_status();            /* NOTE: this function call updates */
  109.                                         /* the global struct CRT in video.h */
  110.                                         /*       REMOVE IF DESIRED          */
  111.          return (uv_mode);
  112.       }
  113.    }   
  114.    return (FAIL);
  115. }
  116.  
  117.  
  118.  
  119. int   enable_ultra   ( void )
  120. {
  121.    /* Enable UltraVision, if loaded and inactive.     */   
  122.    
  123.    if (( ultra_loaded() )&&( !ultra_active() )) {
  124.    
  125.       _AH = 0xcc;
  126.       _AL = 0x02;
  127.       geninterrupt ( 0x10 );            /* enable UV */
  128.  
  129.       _AH = 0x00;
  130.       _AL = CRT.mode;                   /* reset to global CRT */
  131.       geninterrupt ( 0x10 );
  132.  
  133.       get_video_status();               /* NOTE: this function call updates */
  134.                                         /* the global struct CRT in video.h */
  135.                                         /*       REMOVE IF DESIRED          */
  136.                                         
  137.       return ( SUCCESS );
  138.    }
  139.    return ( FAIL );
  140. }
  141.    
  142.    
  143. int    disable_ultra    ( void )
  144. {
  145.    /* Disable UltraVision,  if loaded.  Reset CRT mode to former         
  146.       standard mode, ie, CO80, BW80, or C4350.  
  147.    */ 
  148.  
  149.    if (( ultra_loaded() )&&( ultra_active() )) {
  150.  
  151.       _AH = 0xcc;
  152.       _AL = 0x01;
  153.       geninterrupt ( 0x10 );            /* disable UV */
  154.  
  155.       _AH = 0x00;
  156.       _AL = CRT.mode;                   /* reset to global CRT */
  157.       geninterrupt ( 0x10 );
  158.  
  159.       get_video_status();               /* NOTE: this function call updates */
  160.                                         /* the global struct CRT in video.h */
  161.                                         /*       REMOVE IF DESIRED          */
  162.                                         
  163.       return ( SUCCESS );
  164.    }   
  165.    return ( FAIL );
  166. }
  167.  
  168.  
  169.  
  170. int  bump_rows ( int plus_minus )
  171. {
  172.    /* Rather than trying to call set_ultra_mode() directly, this function
  173.       simply does a "blind bump" of the row count until it achieves success; 
  174.       it does not change the column count.
  175.       
  176.       If UltraVision is active, it returns the new UV mode, else it returns
  177.       FAIL.  Note that it works even if UltraVision is not installed.
  178.    */   
  179.       
  180.    int col_mode, row_mode;
  181.    
  182.    if ( ultra_active() )  {
  183.    
  184.         if ( plus_minus >=0 ) plus_minus = 1;     /*  +1 or -1 only    */
  185.         else                  plus_minus =-1;     /* no zeros allowed! */
  186.  
  187.         col_mode = COL_MODE(CRT.cols);            /* macros in ultra.h */
  188.         row_mode = ROW_MODE(CRT.rows);
  189.  
  190.         do {
  191.              row_mode+=plus_minus;
  192.              if ( row_mode > 3 ) row_mode=0;      /* wrap it around */
  193.              if ( row_mode < 0 ) row_mode=3;      /*   ditto        */
  194.   
  195.         } while (( set_ultra_mode ( UV_MODE[col_mode][row_mode] ))==FAIL); 
  196.  
  197.         return ( UV_MODE[col_mode][row_mode] );
  198.     }    
  199.     else {                    /* either UV is inactive or not present */
  200.  
  201.         if ( CRT.color ) {
  202.              if ( CRT.rows == 25 ) textmode ( C4350 );  /* give it a try  */
  203.              else                  textmode ( C80  );
  204.         }
  205.         else {
  206.              if ( CRT.rows == 25 ) textmode ( C4350 );  /* give it a try  */
  207.              else                  textmode ( BW80  );
  208.         }
  209.           
  210.         get_video_status();             /* update the global CRT */
  211.     }    
  212.  
  213.     return ( FAIL );
  214. }
  215.  
  216.  
  217. int  bump_cols ( int plus_minus )
  218. {
  219.    /* Rather than trying to call set_ultra_mode() directly, this function
  220.       simply does a "blind bump" of the col count until it achieves success; 
  221.       it does not change the row count.
  222.  
  223.       If UltraVision is active, it returns the new UV mode, else it returns
  224.       FAIL.  Note that it works even if UltraVision is not installed.
  225.    */   
  226.  
  227.    int col_mode, row_mode;
  228.    
  229.    if ( ultra_active() )  {
  230.    
  231.         if ( plus_minus >=0 ) plus_minus = 1;
  232.         else                  plus_minus =-1;
  233.  
  234.         col_mode = COL_MODE(CRT.cols);  
  235.         row_mode = ROW_MODE(CRT.rows);
  236.  
  237.         do {
  238.              col_mode+=plus_minus;
  239.              if ( col_mode > 4 ) col_mode=0;
  240.              if ( col_mode < 0 ) col_mode=4;
  241.  
  242.         } while (( set_ultra_mode ( UV_MODE[col_mode][row_mode] ))==FAIL); 
  243.  
  244.         return ( UV_MODE[col_mode][row_mode] );
  245.    }
  246.     else {                    /* either UV is inactive or not present */
  247.  
  248.         if ( CRT.color ) {
  249.              if ( CRT.cols == 80 ) textmode ( C40 );  
  250.              else                  textmode ( C80 );
  251.         }
  252.         else {
  253.              if ( CRT.cols == 80 ) textmode ( BW40 );  
  254.              else                  textmode ( BW80  );
  255.         }
  256.           
  257.         get_video_status();             /* update the global CRT */
  258.     }    
  259.  
  260.    return ( FAIL );
  261. }
  262.  
  263.  
  264. /* end ultra.c */
  265.